<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @property bool $flow 引流:0=否,1=是
 * @property bool $status 状态:0=待审核,1=待发货,2=待收货,3=待评价,4=已完成,5=已取消,6=申请售后,7=待退货,8=退货中,9=售后完成,10=售后取消,11=售后拒绝
 * @property float $hand_amount 上交金额
 * @property float $pay_amount 支付金额
 * @property float $profit_amount 利润
 * @property int $address_id 地址
 * @property int $express_id 快递
 * @property int $goods_id 商品
 * @property int $id
 * @property int $num 数量
 * @property int $seller_id 卖家
 * @property int $spec_id 规格
 * @property int $user_id 用户
 * @property string $createtime
 * @property string $mark 备注
 * @property string $order_no 订单编号
 * @property string $proof 支付凭证
 * @property string $waybill 快递单号
 * @property-read \app\model\Address $address
 * @property-read \app\model\Goods $goods
 * @property-read \app\model\GoodsExpress $express
 * @property-read \app\model\GoodsOrderService $service
 * @property-read \app\model\GoodsSpec $spec
 * @property-read \app\model\User $seller
 * @property-read \app\model\User $user
 * @property-read mixed $status_text
 * @mixin \think\Model
 */
class GoodsOrder extends Model
{
	protected $createTime = 'createtime';
	protected $updateTime = 'updatetime';
	protected $append = [
		'status_text'
	];
	
	function user()
	{
		return $this->belongsTo(User::class,'user_id');
    }
	
	function seller()
	{
		return $this->belongsTo(User::class,'seller_id');
	}
	
	function goods()
	{
		return $this->belongsTo(Goods::class,'goods_id');
	}
	
	function spec()
	{
		return $this->belongsTo(GoodsSpec::class,'spec_id');
	}
	
	function address()
	{
		return $this->belongsTo(Address::class,'address_id');
	}
	
	function express()
	{
		return $this->belongsTo(GoodsExpress::class,'express_id');
	}
	
	function getStatusTextAttr($value,$data)
	{
		$value = $value ?? ($data['status']??0);
		$list = ['0' => '待审核', '1' => '待发货','2'=>'待收货','3'=>'待评价','4'=>'已完成','5'=>'已取消',
			'6'=>'申请售后','7'=>'待退货','8'=>'退货中','9'=>'售后完成','10'=>'售后取消','11'=>'售后拒绝'];
		return $list[$value] ?? '';
    }
	
	function service()
	{
		return $this->hasOne(GoodsOrderService::class,'order_id');
	}
}
